// pages/Detail/Detail.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
      productId: 1,
      productData: {}
    },
  
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const productId = options.id;
      var that = this; // 存储this的引用
  
      this.setData({
        productId: productId
      });
  
      wx.request({
        url: 'https://localhost:7264/api/Details/GetCommodity',
        data: {
          commodityid: productId
        },
        method: "GET",
        success: function (res) {
          // 从服务器返回的数据
          var commodityData = res.data;
          console.log("商品名称：" + commodityData.name);
          console.log("商品价格：" + commodityData.price);
          console.log("商品销量：" + commodityData.sales);
  
          that.setData({ // 使用that调用setData方法
            productData: commodityData
          });
  
          // 打印商品数组
          console.log(commodityData);
        }
      });
    },
  
    // 选择糖分选项
    selectSugarOption: function (e) {
      var index = e.currentTarget.dataset.index;
      var sugarOption = this.data.productData.sugarOptions[index].sugar_Option;
      console.log("选择的糖分选项：" + sugarOption);
      // TODO: 处理选择糖分选项的逻辑
    },
  
    // 选择温度选项
    selectTemperatureOption: function (e) {
      var index = e.currentTarget.dataset.index;
      var temperatureOption = this.data.productData.temperatureOptions[index].temperature_ption;
      console.log("选择的温度选项：" + temperatureOption);
      // TODO: 处理选择温度选项的逻辑
    },
  
    // 选择杯型选项
    selectCupTypeOption: function (e) {
      var index = e.currentTarget.dataset.index;
      var cupTypeOption = this.data.productData.cupTypeOptions[index].cup_ption;
      console.log("选择的杯型选项：" + cupTypeOption);
      // TODO: 处理选择杯型选项的逻辑
    },
  
    // 选择冰块选项
    selectIceOption: function (e) {
      var index = e.currentTarget.dataset.index;
      var iceOption = this.data.productData.iceOptions[index].ice_option;
      console.log("选择的冰块选项：" + iceOption);
      // TODO: 处理选择冰块选项的逻辑
    }
  });